//
//  DestinationViewController.m
//  Travel
//
//  Created by lanou on 15/9/18.
//  Copyright (c) 2015年 TeamThree. All rights reserved.
//

#import "DestinationViewController.h"
#import "LORequestManger.h"
#import "LdestinationCollectionViewCell.h"
#import "LdestinaCollectionReusableView.h"
@interface DestinationViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
{
    UICollectionView *destionationCollevtion;
}
@property (nonatomic,retain) NSMutableArray *modelArray;
@end

@implementation DestinationViewController
- (void)dealloc{
    [_modelArray release];
    [super dealloc];
}



//懒加载
- (NSMutableArray *)modelArray{
    if (!_modelArray) {
        _modelArray  = [[NSMutableArray alloc] init];
    }
    return _modelArray;
}


#pragma mark ------数据解析--------
//目的地数据解析
//- (void)setUpJsonDetination{
//[LORequestManger GET:kDetination success:^(id response) {
//    NSDictionary *dic = (NSDictionary *)response;
//    for (NSDictionary *data in dic[@"elements"]) {
//        
//    }
//    
//} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//    NSLog(@"%@",error);
//}];
//
//
//}



#pragma mark ------程序运行入口--------
- (void)viewDidLoad {
    [super viewDidLoad];
   self.view.backgroundColor = [UIColor colorWithRed:0.969 green:0.949 blue:0.902 alpha:1.000];
    [self setUpCollectionView];
    
    // Do any additional setup after loading the view.
}






#pragma mark ------创建集合视图--------
//集合视图创建
- (void)setUpCollectionView{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.minimumLineSpacing = 10;
    layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    layout.itemSize = CGSizeMake((kWidth - 30)/2, (kWidth - 30)/2);
    destionationCollevtion = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, kWidth, kHeight) collectionViewLayout:layout];
    destionationCollevtion.backgroundColor = [UIColor clearColor];
    destionationCollevtion.delegate = self;
    destionationCollevtion.dataSource = self;
    [self.view addSubview:destionationCollevtion];
    
    [destionationCollevtion registerClass:[LdestinationCollectionViewCell class] forCellWithReuseIdentifier:@"mycell"];
    [destionationCollevtion registerClass:[LdestinaCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"cell"];
    [layout release];
    [destionationCollevtion release];

}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    if (section == 4) {
        return 2;
    }else{
        return 4;
    }

}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 7;
}


//返回cell
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    LdestinationCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"mycell" forIndexPath:indexPath];
    return cell;

}


//返回标头
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    LdestinaCollectionReusableView *reusabcell = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"cell" forIndexPath:indexPath];
    
    return reusabcell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    return CGSizeMake(kWidth, 40);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
